<template>
	<view class="tixian">
		<view class="title">
			快速注册
		</view>
		<view class="tixianbox">
			<view class="item">
				<text>手机号</text>
				<input type="number" v-model="tel" placeholder="请输入手机" />
			</view>
			<view class="item">
				<text>昵称</text>
				<input type="text" v-model="username"  placeholder="请输入昵称" />
			</view>
			<view class="item">
				<text>密码</text>
				<input type="password"  v-model="password" placeholder="请输入密码" />
			</view>
			<view class="item">
				<text>确认密码</text>
				<input type="password" v-model="confimpass"  placeholder="请确认密码" />
			</view>
			<view class="item">
				<text>推广码</text>
				<input type="text" v-model="sj_bh"  placeholder="请输入推广码" />
			</view>
			<view class="item1">
				<view class="maleft">
					<text>验证码</text>
					<input type="text" v-model="code" />
				</view>
				
				<button class="code" :class="{ btnactive: !btnflag }" :disabled="btnflag == 0" @tap="getCode">{{ codemsg }}</button>
			</view>
		</view>
		<view class="bottom">
				<button class="queren"  @tap="register">完成</button>
		</view>
	
		
	</view>
</template>

<script>
		import { mapState } from 'vuex'
export default {
	
	data() {
		return {
			
			codemsg: '点击获取',
			btnflag: true,
		
			code:'',
			username: '',
			tel: '',
			password: '',
			confimpass: '',
			sj_bh:''
			
	
		};
	},
		computed: mapState({
		
		

	}),
	onLoad() {
		
		
	},
	methods: {
			getCode() {
			
			this.code = '';
			
			var tellReg = /^(13[0-9]|14[579]|15[0-3,5-9]|16[6]|17[0135678]|18[0-9]|19[89])\d{8}$/;
			var data = {
				tel: this.tel.replace(/\s*/g,""),
				lb: 1
			};
			if (tellReg.test(this.tel.replace(/\s*/g,""))) {
				this.$store.dispatch('getcode', data)
				.then(res => {
					uni.showToast({
						title: res.data.msg,
						icon: 'none'
					});
					if (res.data.code == 1) {
						var num = 120;
						var timer = setInterval(() => {
							this.btnflag = false;
							this.codemsg = '' + num + 's';
							num--;
							if (num < 1) {
								this.btnflag = true;
								this.codemsg = '点击获取';
								clearInterval(timer);
							}
						}, 1000);
					}
				})
		
				
			} else {
				uni.showToast({
					title: '请登录有效账户',
					icon: 'none'
				});
			}
		},
			register() {
			if (this.tel == '' || this.passwd == '' || this.xingming ||  this.confimpass == '' || this.code == '') {
				uni.showToast({
					title: '注册信息不能为空',
					icon: 'none'
				});
			} else {
				if (this.password != this.confimpass) {
					uni.showToast({
						title: '两次密码输入不一致',
						icon: 'none'
					});
				} else {
					var data = {
						tel: this.tel.replace(/\s*/g,""),
						passwd: this.password.replace(/\s*/g,""),
						xingming: this.username,
						sms_code: this.code,
						 invite_code:this.sj_bh
					};
					this.$store.dispatch('register', data).then(res => {
						if (res.data.code == 1) {
							uni.showToast({
								title: res.data.msg
							});
							try {
								uni.setStorageSync('username', this.tel);
								uni.setStorageSync('password', this.password);
							} catch (e) {
								// error
							}
							uni.navigateTo({
								url: 'login'
							});
						} else if (res.data.code == 0) {
							uni.showToast({
								title: res.data.msg,
								icon: 'none'
							});
						}
					});
				}
			}
		}
	
	
	}
};
</script>

<style lang="scss" scoped >
	.tixian {
		// min-height: calc(100vh - 50upx);
		min-height: 100%;
	   padding: 0 80rpx;
	   display: flex;
	   flex-direction: column;
		.title{
			font-size: 60rpx;
			padding: 60rpx 0;
			
		}
		.tixianbox {
			
			.item {
				background-color: #fff;
				display: flex;
				margin: 0upx 0upx 30upx 0upx;
				// height: 80upx;
				align-items: center;
			   padding-top: 20rpx;
			   padding-bottom: 20rpx;
				font-size: 30upx;
				
				border-bottom: solid 2rpx #d4d4d4;
				text {
					width: 120upx;
				}
				input {
					width: 450upx;
					text-align: right;
				}
				span{
					display: inline-block;
					width: 490upx;
					color: grey;
					// width: 100%;
					text-align: right;
				}
			}
			.item1 {
				margin: 30upx 0upx 0upx 0upx;
				 padding-top: 20rpx;
				
				display: flex;
				flex-direction: row;
				justify-content: space-between;
				view {
					width: 424upx;
					background-color: #ffffff;
					
					display: flex;
					flex-direction: row;
					align-items: center;
					border-bottom:  solid 2rpx #d4d4d4;
					padding-bottom: 20rpx;
					text {
						// padding-left: 40upx;
						font-size: 30upx;
						display: inline-block;
						width: 120upx;
					}
					input {
						// height: 80upx;
						font-size: 28upx;
						
					}
				}
				
				button {
					width: 222rpx;
		height: 60rpx;
					line-height: 60rpx;
					border-radius: 33rpx;
					background-color: #2296f3;
					color: #fff;
					font-size: 28upx;
					margin-left: 30rpx;
				}
			}
		}
		.bottom{
			flex: 1;
		  flex-direction: column;
			align-items: flex-end;
			justify-content: flex-end;
				.queren {
				// position: absolute;
				// left: 0;
				// right: 0;
				width: 600rpx;
				margin: 0 auto;
				// bottom: 100rpx;
				
				margin-top: 100upx;
				// width: 670upx;
				height: 90upx;
				background-color: #2296f3;
					border-radius: 40rpx;
				color: #fff;
				line-height: 90upx;
				font-size: 32upx;
				
			}
		}
	
	}
	
</style>
